<?php
//栈（选进后出）
//php中已经提供了array_push()和array_pop()函数来实现栈。
class Stack{
    public $array=array();
    public $index=0;

    public static function push($stack,$data){
        $stack->array[$stack->index++]=$data;
    }

    public static function pop($stack,&$data){
        if($stack->index==0){
           $data='';
        }else{
            $data=$stack->array[--$stack->index];
        }
        return $data;
    }

    public static function showStack($stack){
        while(Stack::pop($stack,$data)){
            echo $data."</br>";
        }
    }
}


$stack=new Stack();
Stack::push($stack,'1');
Stack::push($stack,'2');
Stack::push($stack,'3');
Stack::push($stack,'4');
Stack::showStack($stack);